<template>
  <el-dialog title="学生注册" :visible.sync="addStudentShow" width="30%">
    <el-form>
      <el-form-item label="名字">
        <el-input v-model="addStudentForm.name" placeholder="请输入姓名"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer">
      <el-button size="small" type="info" @click="close">取消</el-button>
      <el-button size="small" type="primary" @click="createStudent">确定</el-button>
    </div>
  </el-dialog>
</template>
<script>
import {registerStudentApi} from "@/api/qingongjianxue";

export default {
  data(){
    return {
      addStudentForm: {
        name: ''
      }
    }
  },
  props: {
    addStudentShow: {
      type: Boolean,
      default: false
    },
    userInfo: {
      type: Object,
      default: () => {
        return {
          address: '',
          privateKey: '',
          studentId: ''
        }
      }
    }
  },
  methods:{
    //学生注册
    async createStudent(){
      if(!this.addStudentForm.name){
        this.$message.error('请输入姓名')
        return
      }
      const res = await registerStudentApi({
        privateKey: this.userInfo.privateKey,
        name: this.addStudentForm.name,
        studentId: this.userInfo.studentId
      })
      this.addStudentShow = false
      this.$message.success(res.msg)
    },
    close(){
      this.$emit('close')
    }
  }
}
</script>
<style scoped lang="scss">

</style>
